package com.qf.boot2202day03.servlet;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.MathGenerator;
import com.qf.boot2202day03.utils.Constants;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/hutoolcap")
public class HutoolCapcharServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 验证码对象
//        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 100, 2, 4);

        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
        // 设置验证码生成器
        lineCaptcha.setGenerator(new MathGenerator());

        req.getSession().setAttribute(Constants.HUTOOL_CAPCHAR,lineCaptcha);

        lineCaptcha.write(resp.getOutputStream());

    }
}
